<template>
    <div>
        <div>
            <el-dialog class="nyDialog" :visible.sync="is_dialog_show" width="42%" :close-on-click-modal="false"
                :before-close="() => { this.close(); }">
                <div class="overflow-hidden w-full h-full flex flex-col items-center" style="border-radius:4px;">
                    <div class="w-full h-w48 flex items-center px-w20 justify-between bg-caux text-white">
                        <div class="text-f14">{{ m_data.id ? "编辑视频类别" : "添加视频类别" }}</div>
                        <i class="el-icon-circle-close   cursor-pointer" @click.stop="close()"></i>
                    </div>
                    <div class="w-full flex justify-center">
                        <div class="flex flex-col w-w8/12  ">

                            <div class="flex flex-row items-center  w-full h-w50 leading-w50 text-c3 text-f16  mt-w30">
                                <div class=" w-w1/4 text-right pr-w20">类别名称</div>
                                <el-input class="w-w3/4" placeholder="请输入内容" v-model="m_data.name" clearable autofocus>
                                </el-input>
                            </div>

                            <div class="flex flex-row items-start  w-full   text-c3 text-f16  mt-w30">
                                <div class=" w-w1/4 text-right pr-w20  h-w50 leading-w50">类别图片</div>
                                <div class="flex flex-col">
                                    <el-upload class="avatar-uploader" action="" :show-file-list="false"
                                        :on-change="action_select_file" :auto-upload="false" accept="image/png, image/jpeg">
                                        <img v-if="m_data.logo_url" :src="m_data.logo_url" class="avatar">
                                        <i v-else class="el-icon-plus avatar-uploader-icon"></i>
                                    </el-upload>
                                    <div class=" mt-w5 text-f15 text-c6">图片尺寸：94px*92px</div>
                                </div>
                            </div>
                            <div class="flex flex-row items-center  w-full h-w50 leading-w50 text-c3 text-f16  mt-w30">
                                <div class=" w-w1/4 text-right pr-w20">排序</div>
                                <el-input-number class="w-w3/4" v-model="m_data.sort" :step="1" :min="0">
                                </el-input-number>
                            </div>
                        </div>
                    </div>

                    <div class="w-full flex flex-row justify-center mt-w30 mb-w30">
                        <el-button class=" w-w1/5 mr-w20" @click="close">取消</el-button>
                        <el-button class=" w-w1/5 bg-cmain_hover" type="primary" @click="actionSubmit">确定
                        </el-button>
                    </div>
                </div>
            </el-dialog>
        </div>
    </div>
</template>
<script lang="ts">
import uploadFile from "@/utils/DZUploadFile";
import nyMessageToast from "@/utils/NYMessageToast";
import DZModelType from "@/views/视频管理/model/DZModelVideoType";
import { Component, Vue, Prop, Watch } from "vue-property-decorator";

@Component
export default class UiDialogAddVideoType extends Vue {

    @Prop() is_showDialog;

    @Prop() data;

    is_dialog_show = false;

    m_data = new DZModelType();


    created() { }

    mounted() {
    }

    beforeDestroy() { }

    close() {
        this.$emit('nydialog_closed', '');
        this.initDialog();
    }
    initDialog() {
        this.m_data = new DZModelType();
        this.is_dialog_show = false;
    }

    @Watch("is_showDialog")
    watchShowDialog(value: any, oldValue: string) {
        this.is_dialog_show = value;
    }
    @Watch("data")
    watchData(value: any, oldValue: string) {
        if (value) {
            this.m_data = value;
        } else {
            this.m_data = new DZModelType();
        }
    }

    actionSubmit() {
        if (this.m_data.name.nyIsEmpty()) {
            nyMessageToast.warning("请输入分类名称");
            return;
        }
        if (this.m_data.logo.nyIsEmpty()) {
            nyMessageToast.warning("请上传分类图片");
            return;
        }
        this.$emit('nydialog_submit', this.m_data);
        this.close();
    }

    action_select_file(file) {
        if (file.status == "ready") {
            this.m_data.logo_url = URL.createObjectURL(file.raw);
            uploadFile.uploadImage(file.raw,
                (res) => {
                }, (res) => {
                    nyMessageToast.success("图片上传成功")
                    this.m_data.logo = res + "";
                }, (res) => {
                    nyMessageToast.error("图片上传失败")
                    this.m_data.logo_url = "";
                });
        }
    }
}
</script>
<style lang="less" scoped>
/deep/ .el-dialog {
    border-radius: 4px !important;
    border: none;
}

/deep/.el-dialog__body {
    text-align: left;
    // min-height: 22vw;
    padding: 0px;
}

/deep/ .dialog-tips {
    margin-top: 0 !important;
}

/deep/ .el-dialog__footer {
    text-align: right;
}

/deep/.el-dialog__header {
    height: 0px;
    padding: 0;
}

/deep/ .el-icon-close:before {
    content: '';
}

.nyDialog {
    background: none;
}

/deep/ .el-upload {
    border: 1px dashed #d9d9d9;
    border-radius: 6px;
    cursor: pointer;
    position: relative;
    overflow: hidden;
}

/deep/ .el-upload:hover {
    border-color: #409EFF;
}

.avatar-uploader-icon {
    font-size: 28px;
    color: #8c939d;
    width: 100px;
    height: 100px;
    line-height: 100px;
    text-align: center;
}

/deep/ .avatar {
    width: 100px;
    height: 100px;
    display: block;
}
</style>
